<?php 
/**
 * memcache驱动
 * @author Yuwei(yuwei1122@gmail.com)
 *
 */
final class BluePhp_Library_Cache_Drives_Memcache
{
	/**
	 * 服务器连接
	 * @var unknown_type
	 */
	protected $_connection;
	
	/**
	 * 构造函数
	 */
	public function __construct()
	{
		//判断扩展是否安装
		extension_loaded('memcache') or die('memcache extention is not loaded');
		$this->_connection = new Memcache();
		foreach (json_decode(CACHE_CONFIG) as $one)
			$this->_connection->addServer($one[0],$one[1]) or die('Could not connect memcached');
	}
	
	/**
	 * get
	 * @param unknown_type $key
	 */
	public function get($key)
	{
		return $this->_connection->get($key);
	}
	
	/**
	 * set
	 * @param unknown_type $key
	 * @param unknown_type $value
	 * @param unknown_type $time
	 */
	public function set($key,$value,$time)
	{
		return $this->_connection->set($key,$value,MEMCACHE_COMPRESSED,$time);
	}
	
	/**
	 * delete
	 * @param unknown_type $key
	 */
	public function delete($key)
	{
		return $this->_connection->delete($key);
	}
	
	/**
	 * replace
	 * @param unknown_type $key
	 * @param unknown_type $value
	 */
	public function replace($key,$value)
	{
		return $this->_connection->replace($key);
	}
	
	/**
	 * flush
	 */
	public function flush()
	{
		return $this->_connection->flush();
	}
}
?>